package history.hot100;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

// 78. 子集
// 回溯写法：https://leetcode-cn.com/problems/subsets/solution/hui-su-suan-fa-by-powcai-5/
public class LeetCode_78 {
    private List<List<Integer>> result = new ArrayList<>();
    public List<List<Integer>> subsets(int[] nums) {
        if (nums == null || nums.length == 0) return Collections.EMPTY_LIST;
        backtracking(0, new ArrayList(), nums);
        return result;
    }

    private void backtracking(int i, ArrayList temp, int []nums) {
        result.add(new ArrayList<>(temp));
        for (int j = i; j < nums.length; j++) {
            temp.add(nums[j]);
            backtracking(j+1, temp, nums);
            temp.remove(temp.size()-1);
        }
    }
}
